var app = angular.module('webpageApp');

app.directive('treeview', ['$compile', function($compile) {
  return {
    strict: 'E',
    templateUrl: 'src/template/tmpl/treeview.html',
    scope: {
      set: '=',
      add: '&',
      remove: '&',
      choose: '&',
      current: '='
        // add: '&',
    },
    link: function(scope, elem, attrs) {
      scope.select = function(item, e) {
        console.log(item, 'select');
        console.log(e.target, 'target');
        // angular.element(e.target).addClass('selected');
        // 控制选中高亮显示
        angular.element('li.treeview a').removeClass(
          'selected');
        angular.element(e.target).closest('a').toggleClass(
          'selected');
      };
      // 监听set是否变化
      scope.$watch('set', function(v) {
        // console.log(attrs, 'attr');
        $compile(elem.contents())(scope);
      }, true);
    }
  };
}]);
